﻿using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using FutureApp.Users;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace FutureApp.Shop
{
    /// <summary>
    /// 商品模型
    /// </summary>
    [Table("GoodsMoulds")]
    public class GoodsMould : FullAuditedEntity<Guid, User>, IPassivable
    {
        /// <summary>
        /// <see cref="Name"/> 属性的最大长度
        /// </summary>
        public const int MaxNameLength = 50;

        /// <summary>
        /// 类型名
        /// </summary>
        [Required]
        [StringLength(MaxNameLength)]
        public virtual string Name { get; set; }

        /// <summary>
        /// 激活/禁用
        /// </summary>
        public virtual bool IsActive { get; set; } = true;

        /// <summary>
        /// 商品模型特征属性组合
        /// </summary>
        [ForeignKey("MouldId")]
        public virtual ICollection<GoodsMouldAssemble> MouldAssembles { get; set; }

        /// <summary>
        /// 商品模型特征属性组合
        /// </summary>
        [NotMapped]
        public ICollection<GoodsAttribute> Attributes
        {
            get
            {
                return (from assemble in this.MouldAssembles
                        orderby assemble.Order
                        select assemble.Attribute
                        ).ToList();
            }
        }
    }
}
